﻿using System;
using Hjt212Parser;
using log4net;

namespace GatewayBizProcess.Facade
{
    public class Sync
    {
        private static readonly ILog Log = LogManager.GetLogger(typeof(Sync));
        public void DataSync2011(object state)
        {
            while (true)
            {
                var now = DateTime.Now;
                try
                {
                    DataSync.Sync2011();
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                }
                finally
                {
                    var span = (int)(DateTime.Now - now).TotalSeconds;
                    var milliSeconds = 5 * 60 * 1000 - span;
                    if (milliSeconds < 0)
                    {
                        Log.Info("同步2011Gxt平台数据到Zr平台需要" + span + "秒");
                        milliSeconds = 1000;
                    }
                    ThreadUtil.Sleep(milliSeconds);
                }
            }
            // ReSharper disable once FunctionNeverReturns
        }

        public void DataSync2061(object state)
        {
            while (true)
            {
                var now = DateTime.Now;
                try
                {
                    DataSync.Sync2061();
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                }
                finally
                {
                    var span = (int)(DateTime.Now - now).TotalSeconds;
                    var milliSeconds = 30 * 60 * 1000 - span;
                    if (milliSeconds < 0)
                    {
                        Log.Info("同步2061Gxt平台数据到Zr平台需要" + span + "秒");
                        milliSeconds = 1000;
                    }
                    ThreadUtil.Sleep(milliSeconds);
                }
            }
            // ReSharper disable once FunctionNeverReturns
        }
    }
}
